
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            *{
                margin: 0px;
                padding:0px;
                list-style: none;
                background:wheat;
            }
            textarea{
                width: 700px;
                height: 200px;
                margin:10px auto;
                display: block;
                outline: none;
                resize: none;
            }
            button{
                width: 700px;
                margin:10px auto;
                display: block;
                background:greenyellow;
                border:none;
                outline: none;
                line-height: 40px;
                cursor: pointer;
                color:#fff;
            }
            ul{
                width: 800px;
                margin:10px auto;
            }
            ul li{
                background-color: olivedrab;
                margin-bottom: 10px;
                position: relative;
                padding:4px;
            }
            span{
                position: absolute;
                right:-5px;
                top:-5px;
                cursor: pointer;
            }
        </style>
    </head>
    <body>
        <textarea name="" id="txt" cols="30" rows="10"></textarea>
        <button id="btn">微博发布</button>
        <ul id="box">
            <li>
                今天天气很好
                <p>2021-06-10</p>
                <span onclick="del(this)">X</span>
            </li>
        </ul>
 
        <script >
            btn.onclick=function(){
                if(txt.value==''){
                    alert('输入点东西')
                }else{
                    var c=new Date();
                    console.log(c)
                    var year=c.getFullYear()
                    var month=c.getMonth()+1
                    var date=c.getDate()
                    var hour=c.getHours()
                    var min=c.getMinutes()
                    var sec=c.getSeconds()
                    var val=txt.value;
                    var tag=document.createElement('li');
                    tag.innerHTML=` ${val}
                    <p>${year}-${month}-${date}-${hour}:${min}:${sec}</p>
                    <span  onclick="del(this)">X</span>`
                    box.appendChild(tag);
                    txt.value=''
                }
            }
            function del(a){
                a.parentNode.parentNode.removeChild(a.parentNode)
            }
        </script>
    </body>
</html>
